#include "threadPool.h"

int queue_init(taskQueue* queue) {
    memset(queue, 0, sizeof(taskQueue));
    return 0;
}

int enque(taskQueue* queue, Task t) {
    Node* new_node = (Node*)calloc(1, sizeof(Node));
    new_node->task = t;
    if (queue->size == 0) {
        queue->front = new_node;
        queue->rear = new_node;
    } else {
        queue->rear->next = new_node;
        queue->rear = new_node;
    }
    ++queue->size;
    return 0;
}

int deque(taskQueue* queue) {
    Node* cur = queue->front;
    queue->front = cur->next;
    --queue->size;
    if (queue->size == 0) {
        queue->front = NULL;
        queue->rear = NULL;
    }
    free(cur);
    return 0;
}
